package org.oslims.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;

import com.google.gwt.validation.client.NotEmpty;
import com.google.gwt.validation.client.NotNull;
import com.google.gwt.validation.client.Size;

@Entity
public class Analysis extends AbstractBaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3492661535566785523L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@NotEmpty
	private String name;

	@ManyToOne
	@JoinColumn(name = "DEPARTMENT_FK")
	@NotNull
	private Department doneIn;

	private Double estimatedTime;

	private Double estimatedCost;

	@OneToMany(mappedBy = "analysis")
	private List<SOP> sOPs = new ArrayList<SOP>();

	@ManyToMany(mappedBy = "possibleAnalysis", targetEntity = SampleType.class)
	private List<SampleType> validSampleTypes = new ArrayList<SampleType>();

	@ManyToMany(targetEntity = Parameter.class)
	@JoinTable(name = "ANALYSIS_PARAMETER", joinColumns = @JoinColumn(name = "ANALYSIS_ID"), inverseJoinColumns = @JoinColumn(name = "PARAMETER_ID"))
	@Size(minimum = 1)
	@OrderBy("name")
	private List<Parameter> determinedParameters = new ArrayList<Parameter>();

	@NotNull
	private Boolean active = true;

	@OneToMany(mappedBy = "analysis")
	private List<AnalysisResult> analysisResults = new ArrayList<AnalysisResult>();

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Department getDoneIn() {
		return doneIn;
	}

	public void setDoneIn(Department doneIn) {
		this.doneIn = doneIn;
	}

	public Double getEstimatedTime() {
		return estimatedTime;
	}

	public void setEstimatedTime(Double estimatedTime) {
		this.estimatedTime = estimatedTime;
	}

	public Double getEstimatedCost() {
		return estimatedCost;
	}

	public void setEstimatedCost(Double estimatedCost) {
		this.estimatedCost = estimatedCost;
	}

	public List<SOP> getsOPs() {
		return sOPs;
	}

	public void setsOPs(List<SOP> sOPs) {
		this.sOPs = sOPs;
	}

	public List<SampleType> getValidSampleTypes() {
		return validSampleTypes;
	}

	public void setValidSampleTypes(List<SampleType> validSampleTypes) {
		this.validSampleTypes = validSampleTypes;
	}

	public List<Parameter> getDeterminedParameter() {
		return determinedParameters;
	}

	public void setDeterminedParameter(List<Parameter> determinedParameter) {
		this.determinedParameters = determinedParameter;
	}

	public Boolean getActive() {
		return active;
	}

	public void setActive(Boolean active) {
		this.active = active;
	}

	public void setAnalysisResults(List<AnalysisResult> analysisResults) {
		this.analysisResults = analysisResults;
	}

	public List<AnalysisResult> getAnalysisResults() {
		return analysisResults;
	}

	public String toString() {
		return this.name;
	}

}
